/**
 * Load flash of specified URL.
 *
 * @name: loadFlash
 * @author: luoluo
 * @date: 2009-04-21
 * @version: 1.0
 *
 * @param{url}: URL of the flash swf file.
 * @param{proc}: Function to be called after the flash was loaded.
 * @param{delay}: The delay time for waiting flash to be loaded, it depends to your swf file size.
 * @param{minVer}: Requires the minimize version of the flash player to load the swf file.
 * @param{maxVer}: Requires the maximize version of the flash player to load the swf file.
 * 
 * @sample:
 *
 * loadFlash("http://d1.sina.com.cn/200904/15/172213_lt_home_3pt10415.swf", function(flash) {
 *	 alert(flash);
 * }, 1000, 7, 10); 
 *
 */
function loadFlash(/*url, proc, delay, minVer, maxVer*/) {
	if (/MSIE/.test(window.navigator.userAgent)) {
		if (document.readyState != "loaded" &&
			document.readyState != "complete") {
			var args = arguments;
			
			if (window.onload) {
				var onloadProc = window.onload;
			}
			
			window.onload = function() {
				args.callee.apply(window, args);
				
				if (onloadProc) {
					onloadProc();
				}
			}
			return;
		}
	}
	
	var url = arguments[0];
	var proc;
	var delay = 1000;	
	var minVer = -1;
	var maxVer = 100;
	
	if (arguments.length > 1) {
		proc = arguments[1];
	}
	
	if (arguments.length > 2) {
		delay = arguments[2];
	}	
	
	if (arguments.length > 3) {
		minVer = arguments[3];
	}
	
	if (arguments.length > 4) {
		maxVer = arguments[4];
	}

	function getFlashVersion() {
		var flash;
		var version;

		if (/MSIE/.test(window.navigator.userAgent)) {
			flash = new ActiveXObject("ShockwaveFlash.ShockwaveFlash");
			
			if (flash) {
				version = flash.GetVariable("$version");
			}
		} else {
			if (navigator.plugins && navigator.plugins.length > 0) {
				flash = navigator.plugins["Shockwave Flash"];
				
				if (flash) {
					version = flash.description;
				}
			}
		}
		
		if ((m = /\d+/.exec(version))) {
			version = parseInt(m[0]);
			return version;
		}
	}
	
	var version = getFlashVersion();
	
	if (version && (version >= minVer && version <= maxVer)) {
		var id = "swf" + Math.floor(Math.random() * 100000).toString();
	
		var html = "<object id=\"" + id + "\" height=\"0\" width=\"0\" type=\"application/x-shockwave-flash\" " + 
				"codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7\" " + 
				"classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\">\n" +
				"<param name=\"movie\" value=\"" + url + "\" />\n" +
				"<param name=\"quality\" value=\"high\" />\n" +
				"<param name=\"wmode\" value=\"opaque\" />\n" +
				"<param name=\"allowscriptaccess\" value=\"always\" />\n" +
				"<embed id=\"" + id + "\" height=\"0\" width=\"0\" quality=\"high\" wmode=\"opaque\" " +
				"allowscriptaccess=\"aways\" type=\"application/x-shockwave-flash\" " +
				"pluginspage=\"http://www.macromedia.com/go/getflashplayer\" src=\"" + url + "\" />\n" +
				"</object>\n";
				
		var pnl = document.createElement("div");
		pnl.style.display = "none";
		pnl.innerHTML = html;
		
		if (document.body) {
			document.body.appendChild(pnl);
		} else {
			document.documentElement.appendChild(pnl);
		}
		
		var intval = setInterval(function() {
			var flash = document.getElementById(id);
			
			if (flash) {
				clearInterval(intval);
				
				if (proc) {
					if (typeof proc == "function") {
						proc(flash);
					}
				}
			}
		}, delay)
	}
}